package com.santu.edu.supporter.biz.buildings.dao;

import com.santu.edu.supporter.biz.buildings.dao.mapper.BuildingsMapper;
import com.santu.edu.supporter.biz.buildings.pojo.dto.BuildingsDTO;
import com.santu.edu.supporter.biz.buildings.pojo.enums.BuildingsType;
import com.santu.edu.supporter.biz.buildings.pojo.po.BuildingsPO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luoyaoqi
 * @createTime 2024/2/20
 * @description
 */
@Repository
@RequiredArgsConstructor
public class BuildingsDao {

    private final BuildingsMapper buildingsMapper;
    public void addBuilding(BuildingsDTO dto) {
        BuildingsPO item = BuildingsPO.createItem(dto);
        buildingsMapper.insertOne(item);
    }

    public void removeBuilding(String buildingsId) {
        buildingsMapper.removeOne(buildingsId);
    }

    public List<BuildingsDTO> getBuildingsList(BuildingsType buildingsType,String schoolId) {
        List<BuildingsPO> itemList = buildingsMapper.getBuildingsList(buildingsType.getCode(),schoolId);
        return itemList.stream().map(BuildingsDTO::createItem).collect(Collectors.toList());
    }

    public List<BuildingsDTO> getBuildsByIdList(List<String> buildIdList) {
        List<BuildingsPO> itemList = buildingsMapper.selectBuildsByIdList(buildIdList);
        return itemList.stream().map(BuildingsDTO::createItem).collect(Collectors.toList());
    }
}
